<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
try{
String UserName=session.getAttribute("UserName").toString();
String PassWord=session.getAttribute("PassWord").toString();
String UserKind=session.getAttribute("UserKind").toString();

//拿到用户名和密码，保存到session中
/*
在这个界面添加三个三个按钮，一个是招聘信息，职场信息，个人中心
*/
}catch(Exception e){
session.setAttribute("UserName","");
session.setAttribute("UserKind","user.jsp");
}
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>main</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
     <script  src="Js/jquery-3.4.1.min.js" ></script>
      <script src="Js/jquerysession.js"></script>

      <link href="Css/layout.css" rel="stylesheet">
      <link href="Css/header.css" rel="stylesheet">
      <link href="Css/searchresult.css" rel="stylesheet" >
  </head>
  <body>
<%--  js操作写在这里--%>
  <script>
      $(function() {
          try{
              //如何解决空指针报错呢？
          var UserName = "<%=session.getAttribute("UserName").toString()%>";
          var UserKind = "<%=session.getAttribute("UserKind").toString()%>";
          if (UserName!="") {
              //这里如果登录成功就需要把登录注册替换成一个用户头像和用户呢?
              //替换头像
              $("#aindex").replaceWith("<img src='Image/user.png' " +
                  "style='display:inline-block;width:32px;height:20px;margin:5px 10px 5px 10px'/>");
              //替换昵称
              $("#aregis").replaceWith("<a class='aregis'><%=session.getAttribute("UserName").toString()%></a>")
              //这里需要把用户头像更改掉，先不改动，然后我们先修改一下俩个操作按钮
              $(".maindiv").hide()
             }

          //还需要改动下面两个按钮如果是企业就换成另外一个
              if (UserKind=="company.jsp"){
                  $(".userlogin").replaceWith("<div class='userlogin' style='width: 64px;height: 50px;'><a id='auserlogin' href='company.jsp'>企业信息</a></div>");
                  $(".userregister").replaceWith("<div class='userregister' style='width: 64px;height: 50px;'><a id='auseregister' href='company.jsp'>招聘信息</a></div>");
              }else{
                  $(".userlogin").replaceWith("<div class='userlogin' style='width: 64px;height: 50px;'><a id='auserlogin' href='user.jsp'>我的简历</a></div>");
                  $(".userregister").replaceWith("<div class='userregister' style='width: 64px;height: 50px;'><a id='auseregister' href='user.jsp'>我的收藏</a></div>");
              }
              }catch (e) {
             return;
          }
      })

  </script>


<%--  界面写在这里--%>
  <div class="header">
      <div class="in">
          <p class="call">商务合作联系&nbsp;110</p>
          <div class="login">
              <a  id="aindex" href="index.jsp" class="aindex">登录</a>
              <a id="aregis" href="register.jsp" class="aregis">注册</a>
          </div>
          <p class="welcome">医伯乐招聘网站欢迎您&nbsp;</p>
      </div>
  </div>

  <div id="topbar" class="topbar">
      <div class="in">
          <a href="" class="logo">
              <img src="/Image/bole.png"></img>
          </a>
          <div class="nav">
              <a href="main.jsp">首页</a>
              <a href="news.jsp">资讯</a>
              <a href="<%=session.getAttribute("UserKind")%>">我的</a>
          </div>
      </div>
  </div>
<script>
$(document).ready(function () {

    $(".button").click(function () {
        //这里执行搜索逻辑
        //首先将所有的都清零。
        $(".jobmanage").empty();
        var select = $('#select').val();
        //获取下拉框中的第几个
        var content = $('#inputcontent').val();
        //获取搜索框中的值

        $.ajax({
            type: "GET",
            url: "SearchJob.action?select=" + select + "&content=" + content,
            dataType: "json",
            success: function (obj) {

                // window.location.href="searchresult.jsp?select="+select+"&content="+content;
                $(".maindiv").show();

                for (var j = obj.job.length - 1; j >= 0; j--) {
                    $.session.set("jobName", obj.job[j].jobName);
                    $.session.set("jobSalary", obj.job[j].jobSalary);
                    $.session.set("publishTime", obj.job[j].publishTime);
                    $.session.set("jobAddress", obj.job[j].jobAddress);
                    $.session.set("jobNum", obj.job[j].jobNum);
                    $.session.set("userID", obj.job[j].userID);
                    $.session.set("JobID",obj.job[j].jobID)
                    $.ajax({
                        type: "GET",
                        url: "GetCompanyBaseByUser.action?UserID=" + $.session.get("userID"),
                        async: false,
                        dataType: "json",
                        success: function (res) {
                            $("#jobmanage")
                                .prepend(
                                    '<div class="demo"><div class="demoin2" ><div class="click" style="float: left"><span>' + $.session.get("jobName") + '</span>' +
                                    '<span>' + res.json.CompanyName + '</span>' +
                                    '<span>' + $.session.get("jobSalary") + '</span>' +
                                    '<span>' + $.session.get("publishTime") + '</span>' +
                                    '<span>' + $.session.get("jobAddress") + '</span>' +
                                    '<span>' + $.session.get("jobNum") + '</span></div>' +
                                    '<img class="collect" src="Image/heartempty.png" style="text-align: center"></img></div></div>'
                                )


                        },
                        error: function () {

                        }
                    })
                    $.session.set("jobID" + j, obj.job[j].jobID);
                }
            },
            error: function () {

            }
        })

    });

    $("#jobmanage").on('click', '.collect', function () {
        //点击事件
        var is= $(".collect").index(this);
        var index = "jobID" + $(".collect").index(this);
        //这里必须是.delete，否则找不到是第几个！
        var jobID = $.session.get(index);

        //先查重，再插入。

        $.ajax({
            type:"GET",
            url:"JobCollectionExist.action?JobID="+jobID,//这里需要携带jobid
            success:function (res) {
                if(res.job.exist==0){
                    $.ajax({
                        type:"GET",
                        url:"JobCollection.action?JobID="+jobID,
                        success:function (res) {
                            if(res.job.result==1){
                                alert("收藏成功")
                                $(".collect").eq(is).attr("src","Image/heartfill.png")
                            }else{
                                alert("收藏失败")
                            }
                        }
                    })
                }else {
                   alert("已在收藏列表")
                }

            },
            error:function () {

            }
        })
        //先改变形状再添加收藏！
    })


    $("#jobmanage").on('click', '.click', function () {
        //点击事件
        var is= $(".collect").index(this);
        var index = "jobID" + $(".click").index(this);
        //这里必须是.delete，否则找不到是第几个！
        var jobID = $.session.get(index);
        window.location.href="jobdetail.jsp?JobID="+jobID;

    })
})
</script>
  <div id="topcontent" class="topcontent">
      <div class="in">
          <%--这里是搜索框--%>
          <div class="searchcontent">

              <div class="textsearch">

                 <input id="inputcontent" type="text" class="inputstyle" name="static">
                  <select id="select" class="select">
                      <option value="1">关键字</option>
                      <option value="2">工作地点</option>
                      <option value="3">工作名称</option>
                  </select>
              </div>
          <%--这里是搜索按钮--%>
              <div class="btnsearch">
                  <input type="button" class="button" value="搜&nbsp;&nbsp;索">
              </div>
              <div class="line"></div>
              <div class="recommend">
                  <p>热门推荐:</p>
                  &nbsp;&nbsp;
                  <a href="">内科</a>
                  <a href="">外科</a>
                  <a href="">妇科</a>
                  <a href="">儿科</a>
                  <a href="">脑科</a>
                  <a href="">骨科</a>
                  <a href="">眼科</a>
                  <a href="">精神科</a>
                  <a href=" ">耳鼻喉科</a>
              </div>
          </div>


<%--这里是用户登录和注册，当用户登录以后这两个按钮变成其他的--%>
          <div class="user">
              <div class="userphoto">
                  <a href="">
                      <img src="/Image/user.png">
                      </img>
                  </a>
              </div>
              <div class="useroperate">
                  <div class="userlogin">
                      <a id="auserlogin" href="index.jsp">登录</a>
                  </div>
                  <div class="userregister">
                      <a id="auserregister" href="register.jsp">注册</a>
                  </div>
              </div>
          </div>
      </div>
  </div>
<div class="maindiv">
    <div class="demo">
        <div class="demoin">
            <span>职位名称</span><span>公司名称</span><span>薪资待遇</span><span>发布时间</span>
            <span>工作地点</span><span>招聘数量</span><span>马上收藏</span>
        </div>
    </div>
    <div id="jobmanage" class="jobmanage">
        <%--通过css代码美化这个界面--%>
        <%--这里用来填充所有的招聘，然后高度自动增加，只需要通过jquery将相关的代码放入即可--%>
        <%--        这个界面可以不要当点击搜索的时候，将下面影藏起来，展示这个即可--%>
    </div>
</div>
  <div class="cresume">
      <div class="in">
          <a href="">立即创建简历，发现好工作</a>
          <em class="e_icon">
          </em>
      </div>
  </div>
  <div class="container">
      <div class="city">
          <span>城市求职</span>
          <div class="list">
              <a href="">北京</a>
              <a href="">上海</a>
              <a href="">广州</a>
              <a href="">南京</a>
              <a href="">长沙</a>
              <a href="">武汉</a>
              <a href="">天津</a>
              <a href="">广东</a>
              <a href="">深圳</a>
              <a href="">杭州</a>
              <a href="">合肥</a>
              <a href="">六安</a>
              <a href="">芜湖</a>
              <a href="">沈阳</a>
              <a href="">无锡</a>
              <a href="">桂林</a>
              <a href="">三亚</a>
              <a href="">香港</a>
          </div>
          <a href="">更多</a>
          <em class="c_icon"></em>
      </div>

      <div class="recommend">

          <div class="hlist">
              <div class="e">
                  <p class="tie">
                            <span class="e_icon">
                                <a href="">外科</a>
                            </span>
                  </p>
                  <a href="">
                      <span class="at">神经外科</span><em>(1000)</em>
                  </a>
                  <br>
                  <a href="">
                      <span class="at">整形外科</span><em>(1000)</em>
                  </a>
                  <br>
                  <a href="">
                      <span class="at">心胸外科</span><em>(1000)</em>
                  </a>

              </div>

              <div class="e">
                  <p class="tie">
                            <span class="e_icon">
                                <a href="">内科</a>
                            </span>
                  </p>
                  <a href="">
                      <span class="at">神经内科</span><em>(1000)</em>
                  </a>
                  <br>
                  <a href="">
                      <span class="at">心血管内科</span><em>(1000)</em>
                  </a>
                  <br>
                  <a href="">
                      <span class="at">血液内科</span><em>(1000)</em>
                  </a>

              </div>
              <div class="e">
                  <p class="tie">
                            <span class="e_icon">
                                <a href="">职业选择</a>
                            </span>
                  </p>
                  <a href="">
                      <span class="at">医师科</span><em>(1000)</em>
                  </a>
                  <br>
                  <a href="">
                      <span class="at">护士科</span><em>(1000)</em>
                  </a>
                  <br>
                  <a href="">
                      <span class="at">信息科</span><em>(1000)</em>
                  </a>

              </div>
              <div class="e">
                  <p class="tie">
                            <span class="e_icon">
                                <a href="">企业招聘</a>
                            </span>
                  </p>
                  <a href="">
                      <span class="at">北京协和医院</span><em>(1000)</em>
                  </a>
                  <br>
                  <a href="">
                      <span class="at">长沙湘雅医院</span><em>(1000)</em>
                  </a>
                  <br>
                  <a href="">
                      <span class="at">上海中山医院</span><em>(1000)</em>
                  </a>

              </div>

              <div class="cn hserver">
                  <a href="" class="tie">企业服务</a>
                  <div class="hlst">
                      <span><a href="">人事招聘</a></span>
                      <span><a href="">调研中心</a></span>
                      <span><a href="">企业培训</a></span>
                      <span><a href="">典范雇主</a></span>
                      <span><a href="">在线测评</a></span>
                      <span><a href="">薪酬调查</a></span>
                  </div>
                  <a href="" class="cln">企业入口</a>
              </div>
          </div>
      </div>
  </div>

  <div class="footer">
      <div class="in">
          <div class="nag">
              <div class="e e_first">
                  <label>销售热线：</label>
                  123-456-789<br>
                  <label>客服热线：</label>
                  110-119-120<br>
                  <label>Email：</label>
                  10000@qq.com
              </div>
              <div class="e">
                  <p class="tie">
                            <span class="e_icon">
                                <a href="">简介</a>
                            </span>
                  </p><br>
                  <a href="">
                      <span class="at">关于我们</span><em>(1000)</em>
                  </a><br>
                  <a href="">
                      <span class="at">服务声明</span><em>(1000)</em>
                  </a><br>
                  <a href="">
                      <span class="at">媒体报道</span><em>(1000)</em>
                  </a>

              </div>
              <div class="e">
                  <p class="tie">
                            <span class="e_icon">
                                <a href="">合作</a>
                            </span>
                  </p><br>
                  <a href="">
                      <span class="at">加入我们</span><em>(1000)</em>
                  </a><br>
                  <a href="">
                      <span class="at">联系我们</span><em>(1000)</em>
                  </a><br>
                  <a href="">
                      <span class="at">友情链接</span><em>(1000)</em>
                  </a>
              </div>
              <div class="e">
                  <p class="tie">
                            <span class="e_icon">
                                <a href="">帮助</a>
                            </span>
                  </p><br>
                  <a href="">
                      <span class="at">帮助中心</span><em>(1000)</em>
                  </a><br>
                  <a href="">
                      <span class="at">常见问题</span><em>(1000)</em>
                  </a><br>
                  <a href="">
                      <span class="at">新手引导</span><em>(1000)</em>
                  </a>
              </div>
              <div class="e">
                  <p class="tie">
                            <span class="e_icon">
                                <a href="">导航</a>
                            </span>
                  </p><br>
                  <a href="">
                      <span class="at">网站地图</span><em>(1000)</em>
                  </a><br>
                  <a href="">
                      <span class="at">职位搜索</span><em>(1000)</em>
                  </a><br>
                  <a href="">
                      <span class="at">简历中心</span><em>(1000)</em>
                  </a>
              </div>
          </div>
      </div>
  </div>
  </body>
</html>